import { IPSAjaxControl } from './ipsajax-control';
import { IPSControlAction } from './ipscontrol-action';
import { PSControlImpl } from './pscontrol-impl';

export class PSAjaxControlImpl extends PSControlImpl implements IPSAjaxControl {
  protected user2pscontrolaction: IPSControlAction | null = null;

  getUser2PSControlAction(): IPSControlAction | null {
    if (this.user2pscontrolaction != null) return this.user2pscontrolaction;
    const value = this.M.getUser2PSControlAction;
    if (value == null) {
      return null;
    }
    this.user2pscontrolaction = this.getPSControlHandlerMust().findPSControlHandlerAction(value);
    return this.user2pscontrolaction;
  }

  get user2PSControlAction(): IPSControlAction | null {
    return this.getUser2PSControlAction();
  }

  getUser2PSControlActionMust(): IPSControlAction {
    const value = this.getUser2PSControlAction();
    if (value == null) {
      throw new Error('未指定用户自定义行为2');
    }
    return value;
  }

  protected userpscontrolaction: IPSControlAction | null = null;

  getUserPSControlAction(): IPSControlAction | null {
    if (this.userpscontrolaction != null) return this.userpscontrolaction;
    const value = this.M.getUserPSControlAction;
    if (value == null) {
      return null;
    }
    this.userpscontrolaction = this.getPSControlHandlerMust().findPSControlHandlerAction(value);
    return this.userpscontrolaction;
  }

  get userPSControlAction(): IPSControlAction | null {
    return this.getUserPSControlAction();
  }

  getUserPSControlActionMust(): IPSControlAction {
    const value = this.getUserPSControlAction();
    if (value == null) {
      throw new Error('未指定用户自定义行为');
    }
    return value;
  }

  get autoLoad(): boolean {
    return this.M.autoLoad != null ? this.M.autoLoad : true;
  }

  get enableItemPrivilege(): boolean {
    return this.M.enableItemPrivilege != null ? this.M.enableItemPrivilege : false;
  }

  get showBusyIndicator(): boolean {
    return this.M.showBusyIndicator != null ? this.M.showBusyIndicator : true;
  }

  get cls(): string {
    return 'PSAjaxControlImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.IPSAjaxControl') return true;
    return super.instanceof(cls);
  }
}
